#include "mymessagebox.h"

MyMessageBox::MyMessageBox(QWidget *parent, MsgBoxType type, QString text) : QDialog(parent)
{
    initState();

    if(type == MsgBoxType_Info)
    {
        initInfo(text);
    }
    else if(type == MsgBoxType_Warn)
    {
        initWarn(text);
    }
    else
    {
        initError(text);
    }

}

void MyMessageBox::initState()
{
    this->resize(350,140);
    //this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    this->setWindowFlags( Qt::Dialog);

    this->setStyleSheet("QWidget{background-color:rgb(40, 80, 120); border-radius: 10px;}");


    labPic = new QLabel(this);
    labNote = new QLabel(this);
    btnSure = new QPushButton("ok",this);
    //btnCancle = new QPushButton("取消",this);

    connect(btnSure,&QPushButton::clicked,this,&MyMessageBox::dealbtnSureClicked);
    //connect(btnCancle,&QPushButton::clicked,this,&MessageBox::dealbtnCancelClicked);
}

void MyMessageBox::initWarn(const QString &text)
{
    this->setWindowTitle("警告");
    int width = this->width();
    QSize size = this->size();

    labPic->setStyleSheet("image:url(:/images/resource/blueCircle.png)");
    labPic->setGeometry(width*0.08,25,40,40);

    labNote->setStyleSheet("color:white");
    labNote->setAlignment(Qt::AlignLeft);
    labNote->setGeometry(width*0.1 + 50,35,width,30);

    QFont font("Microsoft YaHei UI", 12); // 字体名称和大小
    labNote->setFont(font);
    labNote->setText(text);

    btnSure->setGeometry(width*0.75,size.height()-35,80,30);
    btnSure->setStyleSheet("QPushButton{border-radius:5px;border:None;margin:0px;background-color:#3498db;}"
                           "QPushButton:hover{border:None;margin:0px;background-color:rgb(60, 175, 252);}"
                           "QPushButton:pressed{	border:None;margin:0px;background-color:#27AE60;}");

    //btnCancle->setGeometry(width*0.6,110,80,30);
    //btnCancle->setStyleSheet("QPushButton{color:white; border-radius: 5px; background-color:rgb(43,34,45)}"
    //                         "QPushButton:hover{background-color:blue}"
    //                       "QPushButton:pressed{background-color:blue}");

}

void MyMessageBox::initError(const QString &text)
{
    int width = this->width();
    this->setWindowTitle("错误");
    labPic->setStyleSheet("image:url(:/image/msg_error.png)");
    labPic->setGeometry(width*0.5-20,10,40,40);

    labNote->setStyleSheet("color:white");
    labNote->setAlignment(Qt::AlignCenter);
    labNote->setGeometry(0,70,width,20);
    labNote->setText(text);

    btnSure->setGeometry(width*0.5-40,110,80,30);
    btnSure->setStyleSheet("QPushButton{color:white; border-radius: 5px; background-color:rgb(43,34,45)}"
                           "QPushButton:hover{background-color:blue}"
                           "QPushButton:pressed{background-color:blue}");

    btnCancle->hide();
}

void MyMessageBox::initInfo(const QString &text)
{
    this->setWindowTitle("提示");
    int width = this->width();
    QSize size = this->size();

    labPic->setStyleSheet("image:url(:/resource/blueCircle.png)");
    labPic->setGeometry(width*0.08,25,40,40);

    labNote->setStyleSheet("color:white");
    labNote->setAlignment(Qt::AlignLeft);
    labNote->setGeometry(width*0.1 + 50,35,width,30);

    QFont font("Microsoft YaHei UI", 12); // 字体名称和大小
    labNote->setFont(font);
    labNote->setText(text);

    btnSure->setGeometry(width - 100,size.height()- 50,80,30);
    btnSure->setStyleSheet("QPushButton{border-radius:5px;border:None;margin:0px;background-color:#3498db;}"
                           "QPushButton:hover{border:None;margin:0px;background-color:rgb(60, 175, 252);}"
                           "QPushButton:pressed{	border:None;margin:0px;background-color:#27AE60;}");

}

void MyMessageBox::dealbtnSureClicked()
{
    this->accept();
}

void MyMessageBox::dealbtnCancelClicked()
{
    this->reject();
}

